package com.tanhua.server.service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.common.mapper.BlackListMapper;
import com.tanhua.common.pojo.BlackList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Auther: you
 * @Date: 2021/06/09/19:31
 * @Description:
 */
@Service
public class BlackListService {
    @Autowired
    private BlackListMapper blackListMapper;

    public IPage<BlackList> queryBlackList(Long userId, Integer page, Integer pageSize) {
        QueryWrapper<BlackList> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        queryWrapper.orderByDesc("created");

        return blackListMapper.selectPage(new Page<BlackList>(page, pageSize), queryWrapper);
    }

    public Boolean removeBlackListByUserId(Long userId, Long blackListUserId) {
        QueryWrapper<BlackList> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        queryWrapper.eq("black_user_id",blackListUserId);
        return blackListMapper.delete(queryWrapper) > 0;
    }
}
